package top.yueyazhui.vhr.controller.Sal;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiImplicitParam;
import io.swagger.annotations.ApiImplicitParams;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;
import top.yueyazhui.vhr.bean.Response;
import top.yueyazhui.vhr.bean.ResponsePage;
import top.yueyazhui.vhr.model.Employee;
import top.yueyazhui.vhr.model.Salary;
import top.yueyazhui.vhr.service.EmployeeService;
import top.yueyazhui.vhr.service.SalaryService;

import java.util.Date;
import java.util.List;

@RestController
@RequestMapping("/Sal/SalSobConfig")
@Api(tags = "员工账套设置")
public class SalSobConfigController {

    @Autowired
    EmployeeService employeeService;
    @Autowired
    SalaryService salaryService;

    @GetMapping("/")
    @ApiOperation(value = "分页查询员工", notes = "分页查询员工")
    public ResponsePage getAllEmployeeByPageWithSalary(@RequestParam(defaultValue = "1") Integer page, @RequestParam(defaultValue = "20") Integer size) {
        return employeeService.getAllEmployeeByPageWithSalary(page, size);
    }

    @GetMapping("/salaries")
    @ApiOperation(value = "查询工资账套", notes = "查询所有的工资账套")
    public List<Salary> getAllSalary() {
        return salaryService.getAll();
    }

    @PutMapping("/")
    @ApiOperation(value = "编辑工资账套", notes = "编辑工资账套")
    @ApiImplicitParams({
            @ApiImplicitParam(name = "employeeId", value = "员工ID", required = true),
            @ApiImplicitParam(name = "salaryId", value = "薪资账套ID", required = true)
    })
    public Response update(@RequestParam() Integer employeeId, @RequestParam() Integer salaryId) {
        Integer result = employeeService.updateEmployeeSalaryById(employeeId, salaryId);
        if(result == 1 || result == 2) {
            return Response.success("更新成功");
        }
        return Response.error("更新失败");
    }
}
